////////////////////////////////////////////////////////////////////////////////
//
//  FLEX USER GROUP HOKURIKU
//  Copyright 2009 Flex User Group Hokuriku
//  All Rights Reserved.
// 
//  NOTICE: Flex User Group Hokuriku permits you to use, 
//  modify, and distribute this file 
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
package net.fxug.hokuriku.chocolat.view
{
    import flash.display.NativeWindow;
    import flash.display.NativeWindowInitOptions;
    import flash.display.NativeWindowSystemChrome;
    import flash.display.NativeWindowType;
    import flash.display.Screen;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;

    public class SessionTimeUp extends NativeWindow
    {
        private const GUTTER:int = 60;

        private const format:TextFormat = new TextFormat(null, 124, 0xffffff, true);

        public function SessionTimeUp()
        {
            var options:NativeWindowInitOptions = new NativeWindowInitOptions();
            options.type = NativeWindowType.LIGHTWEIGHT;
            options.systemChrome = NativeWindowSystemChrome.NONE;
            options.transparent = true;
            super(options);

            initializeContents();
        }

        private function initializeContents():void
        {
            this.stage.align = StageAlign.TOP_LEFT;
            this.stage.scaleMode = StageScaleMode.NO_SCALE;

            this.alwaysInFront = true;
            this.width = Screen.mainScreen.bounds.width - GUTTER * 2;
            this.height = Screen.mainScreen.bounds.height - GUTTER * 2;
            this.x = GUTTER;
            this.y = GUTTER;

            var background:Sprite = new Sprite();
            background.graphics.beginFill(0x333333);
            background.graphics.drawRoundRect(GUTTER, GUTTER, this.width, this.height, 20, 20);

            this.stage.addChild(background);

            var timeUp:TextField = new TextField();
            timeUp.text = "Time up!";
            timeUp.setTextFormat(format);
            timeUp.scaleX = 2;
            timeUp.scaleY = 2;
            this.stage.addChild(timeUp);
            timeUp.x = (this.width - timeUp.textWidth * timeUp.scaleX) / 2;
            timeUp.y = (this.height - timeUp.textHeight * timeUp.scaleY) / 2;
            timeUp.width = timeUp.textWidth * timeUp.scaleX;
            timeUp.height = timeUp.textHeight * timeUp.scaleY;

            this.stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
        }

        private function mouseDownHandler(event:MouseEvent):void
        {
            super.close();
        }
    }
}